<script>
import ElementUI from 'element-ui'; 
const { Select } = ElementUI; 
import { getValueByPath } from 'element-ui/src/utils/util';
export default {
extends: Select,
props: {
    labelKey: {
      type: String,
      default: 'label'
    },
    valueKey: {
      type: String,
      default: 'value'
    }
  },
 methods:{
  getOption(value) {
    let option;
    const isObject = Object.prototype.toString.call(value).toLowerCase() === '[object object]';
    const isNull = Object.prototype.toString.call(value).toLowerCase() === '[object null]';
    const isUndefined = Object.prototype.toString.call(value).toLowerCase() === '[object undefined]';
    
    for (let i = this.cachedOptions.length - 1; i >= 0; i--) {
     const cachedOption = this.cachedOptions[i];
     const isEqual = isObject
      ? getValueByPath(cachedOption.value, this.valueKey) === getValueByPath(value, this.valueKey)
      : cachedOption.value === value;
     if (isEqual) {
      option = cachedOption;
      break;
     }
    }
    if (option) return option;
    //getValueByPath(value, this.labelKey)
    const label = (!isObject && !isNull && !isUndefined)
     ? String(value) : value[this.$attrs.labelKey] || '';

    let newOption = {
     value: value,
     currentLabel: label
    };
    if (this.multiple) {
     newOption.hitState = false;
    }
    return newOption;
   },
  }
}
</script>